package com.lzy.health.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.lzy.health.common.MessageConst;
import com.lzy.health.entity.PageResult;
import com.lzy.health.entity.QueryPageBean;
import com.lzy.health.entity.Result;
import com.lzy.health.pojo.CheckItem;
import com.lzy.health.service.CheckItemService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

/**
 * @Description:
 * @Author
 * @Date 2021/8/30
 * @Version 1.0
 */
@Slf4j
@RestController
@RequestMapping("checkItem")
public class CheckItemController {
    @Reference
    private CheckItemService checkItemService;
    @PostMapping("add")
    public Result add(@RequestBody CheckItem checkItem){
        log.info("[检查项-新增]data:{}",checkItem);
        checkItemService.add(checkItem);
        return new Result(true, MessageConst.ADD_CHECKITEM_SUCCESS);
    }
    @GetMapping("findPage")
    public Result findPage(QueryPageBean queryPageBean) {
        log.info("[检查项-分页查询]data:{}", queryPageBean);
        //rpc查询数据
        PageResult pageResult = checkItemService.pageQuery(queryPageBean);
        //封装返回结果
        return new Result(true,MessageConst.ACTION_SUCCESS, pageResult);
    }
    @RequestMapping ("delete")
    public Result delete(Integer id){
        log.info("[检查项-根据id删除]id：{}",id);
        //RPC调用处理业务
        checkItemService.delete(id);
        return new Result(true,MessageConst.DELETE_CHECKITEM_SUCCESS);
    }
    @GetMapping("findById/{id}")
    public Result findById(Integer id){
        log.info("[检查项-根据id查询]id：{}",id);
        CheckItem checkItem=checkItemService.findById(id);
        return new Result(true,MessageConst.QUERY_CHECKGROUP_SUCCESS,checkItem);
    }
    @PostMapping("edit")
    public Result edit(@RequestBody CheckItem checkItem){
        log.info("[检查项-编辑]data:", checkItem);
        checkItemService.edit(checkItem);
        return new Result(true,MessageConst.EDIT_CHECKITEM_SUCCESS);
    }
}
